package com.pur.zsms.supplier.dao.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.pur.zsms.common.dao.GenericDao;
import com.pur.zsms.common.dao.JpaTemplate;
import com.pur.zsms.common.exception.GenericException;
import com.pur.zsms.common.support.PageController;
import com.pur.zsms.common.support.PaginationSupport;
import com.pur.zsms.common.vo.CommonType;
import com.pur.zsms.ordercustommanage.po.OrderSupplierMaterPo;
import com.pur.zsms.ordercustommanage.po.OrderSupplierMaterRealPo;
import com.pur.zsms.ordercustommanage.po.OrderSupplierPo;
import com.pur.zsms.ordercustommanage.vo.OrderSupplierVo;
import com.pur.zsms.supplier.dao.SupplierOrderDao;
import com.pur.zsms.supplier.po.SupplierPo;

@Repository("supplierOrderDao")
@Transactional
public class SupplierOrderDaoImpl extends GenericDao implements SupplierOrderDao {

	@Override
	public PaginationSupport listSupplierOrder(PageController pageController, OrderSupplierVo orderSupplierVo) throws GenericException {
		StringBuffer ql = new StringBuffer();
		ql.append(" SELECT o.oid, o.ord_id, o.ord_cust_id, o.ord_sup_id, o.ord_state, o.ord_date , o.ord_day, o.update_time, o.insert_by, o.ord_value, b.shop_name, c.sup_companyname,o.ord_payment_state,o.ord_value_real,o.commit_deliver_state,o.`ord_value_real_cost`, REPLACE(FORMAT((o.`ord_value_real`-o.ord_value_real_cost)*100/o.`ord_value_real`,2),',','') , REPLACE(FORMAT(  o.`ord_value_real` - o.ord_value_real_cost, 2),',',''),(SELECT s.code FROM t_supplier_shop s WHERE s.sup_id = o.`ord_sup_id` AND s.shop_id = b.`shop_id`) ,o.ord_state_sup ,UNIX_TIMESTAMP(o.ord_date) AS ordDateUnix FROM t_order_supplier o ,t_shop b,t_supplier c WHERE o.ord_cust_id = b.shop_id AND o.ord_sup_id = c.sup_id ");

		if (orderSupplierVo.getOrdId() != 0) {
			ql.append(" and o.ord_id  = '");
			ql.append(orderSupplierVo.getOrdId());
			ql.append("'");
		}

		if (orderSupplierVo.getOrdDate() != null && !orderSupplierVo.getOrdDate().equals("")) {
			ql.append(" and o.ord_date  = '");
			ql.append(orderSupplierVo.getOrdDate());
			ql.append("'");
		}
		if (orderSupplierVo.getOrdState() != 0) {
			ql.append(" and o.ord_state  = '");
			ql.append(orderSupplierVo.getOrdState());
			ql.append("'");
		}
		if (orderSupplierVo.getOrdCustName() != null && !orderSupplierVo.getOrdCustName().equals("")) {
			ql.append(" and b.shop_name like '%");
			ql.append(orderSupplierVo.getOrdCustName());
			ql.append("%'");
		}

		if (orderSupplierVo.getOrdSupId() != 0) {
			ql.append(" and o.ord_sup_id  = '");
			ql.append(orderSupplierVo.getOrdSupId());
			ql.append("'");
		}

		if (orderSupplierVo.getCompanyId() != 0) {
			ql.append(" AND EXISTS (SELECT 1 FROM t_shop s WHERE s.shop_id = b.shop_id AND s.company_user ='" + orderSupplierVo.getCompanyId()
					+ "' ) ");
		}

		if (orderSupplierVo.getOrdCustId() != 0) {
			ql.append(" AND b.`shop_id` = '" + orderSupplierVo.getOrdCustId() + "' ");
		}

		ql.append(" ORDER BY  ordDateUnix  DESC,o.ord_id DESC");

		return this.findByNativeQuery(ql.toString(), pageController);

	}

	@Override
	public PaginationSupport findSupCheck(PageController pageController, OrderSupplierVo orderSupplierVo) throws GenericException {
		StringBuffer ql = new StringBuffer();
		ql.append(" SELECT o.oid, o.ord_id, o.ord_cust_id, o.ord_sup_id, o.ord_state, o.ord_date , o.ord_day, o.update_time, o.insert_by, o.ord_value, b.shop_name, c.sup_companyname,o.ord_payment_state,o.ord_value_real,o.commit_deliver_state,o.`ord_value_real_cost`,FORMAT((o.`ord_value_real`-o.ord_value_real_cost)*100/o.`ord_value_real`,2),o.`ord_value_real`-o.ord_value_real_cost FROM t_order_supplier o ,t_shop b,t_supplier c WHERE o.ord_cust_id = b.shop_id AND o.ord_sup_id = c.sup_id ");

		if (orderSupplierVo.getOrdDate() != null && !orderSupplierVo.getOrdDate().equals("")) {
			ql.append(" and o.ord_date  = '");
			ql.append(orderSupplierVo.getOrdDate());
			ql.append("'");
		}
		if (orderSupplierVo.getOrdState() != 0) {
			ql.append(" and o.ord_state  = '");
			ql.append(orderSupplierVo.getOrdState());
			ql.append("'");
		}
		if (orderSupplierVo.getOrdCustName() != null && !orderSupplierVo.getOrdCustName().equals("")) {
			ql.append(" and b.shop_name like '%");
			ql.append(orderSupplierVo.getOrdCustName());
			ql.append("%'");
		}

		if (orderSupplierVo.getOrdSupId() != 0) {
			ql.append(" and o.ord_sup_id  = '");
			ql.append(orderSupplierVo.getOrdSupId());
			ql.append("'");
		}

		ql.append(" AND o.ord_date >='" + orderSupplierVo.getOrdDateStart() + "' AND o.ord_date <='" + orderSupplierVo.getOrdDateEnd() + "'");

		if (orderSupplierVo.getCustIdAll() != null && !orderSupplierVo.getCustIdAll().equals("")) {
			ql.append("AND o.ord_cust_id IN(" + orderSupplierVo.getCustIdAll() + ")");

		}
		ql.append(" ORDER BY  o.ord_id");

		return this.findByNativeQuery(ql.toString(), pageController);

	}

	public List getOrderSupMaterReal(String ordId, String ordCustId, String ordSupId) throws GenericException {

		StringBuffer ql = new StringBuffer();
		ql.append("SELECT a.ord_mater_id,a.ord_mater_weight,a.ord_mater_level  FROM t_order_supplier_mater_reality a WHERE  a.ord_id = '" + ordId
				+ "' AND a.ord_sup_id = '" + ordSupId + "' ");
		List list = this.entityManager.createNativeQuery(ql.toString()).getResultList();
		return list;
	}

	public List<OrderSupplierMaterRealPo> getOrderSupMaterRealForInStore(String ordId, String ordCustId, String ordSupId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o From  OrderSupplierMaterRealPo o where o.ordId = '" + ordId + "' and o.ordSupId = '" + ordSupId
				+ "' and o.returnGoods != '1' and o.ordMaterWeight !='0'");
		List<OrderSupplierMaterRealPo> list = template.find(ql.toString(), null);
		return list;
	}

	public List<OrderSupplierMaterRealPo> getOrderSupMaterRealForMaterCost(String orderDate, int ordSupId, int materId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o From  OrderSupplierMaterRealPo o,OrderSupplierPo s where s.ordId = o.ordId and o.ordSupId = '" + ordSupId
				+ "' and s.ordDate='" + orderDate + "' and  o.ordMaterId = '" + materId + "' and o.returnGoods != '1' and o.ordMaterWeight !='0'");
		List<OrderSupplierMaterRealPo> list = template.find(ql.toString(), null);
		return list;
	}

	public List getOrderSupMaterNeed(String ordId, String ordCustId, String ordSupId) throws GenericException {

		StringBuffer ql = new StringBuffer();
		ql.append("SELECT a.ord_mater_id,a.ord_mater_weight,a.ord_mater_level  FROM t_order_supplier_mater_need a WHERE  a.ord_id = '" + ordId
				+ "' AND a.ord_sup_id = '" + ordSupId + "' ");
		List list = this.entityManager.createNativeQuery(ql.toString()).getResultList();
		return list;
	}

	public OrderSupplierMaterPo getOrderSupMaterByOrdIdMaterId(String ordId, String ordMaterId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierMaterPo o where o.ordId='" + ordId + "' and o.ordMaterId='" + ordMaterId + "' ");
		List<OrderSupplierMaterPo> list = template.find(ql.toString(), null);
		return list.get(0);
	}

	public List<OrderSupplierMaterPo> getOrderSupMaterByOrdIdSupId(String ordId, String ordSupId, String ordMaterId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierMaterPo o where o.ordId='" + ordId + "' and o.ordSupId='" + ordSupId + "' and o.ordMaterId !=  '" + ordMaterId
				+ "'");
		List<OrderSupplierMaterPo> list = template.find(ql.toString(), null);
		return list;
	}

	public OrderSupplierMaterRealPo getOrderSupMaterRealByOrdIdMaterId(int ordId, int ordMaterId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierMaterRealPo o where o.ordId='" + ordId + "' and o.ordMaterId='" + ordMaterId + "' ");
		List<OrderSupplierMaterRealPo> list = template.find(ql.toString(), null);
		return list.get(0);
	}

	public OrderSupplierMaterRealPo getOrderSupMaterRealByOrdIdMaterIdSupId(int ordId, int ordMaterId, int ordSupId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierMaterRealPo o where o.ordId='" + ordId + "' and o.ordMaterId='" + ordMaterId + "' and o.ordSupId = '"
				+ ordSupId + "'");
		List<OrderSupplierMaterRealPo> list = template.find(ql.toString(), null);
		return list.get(0);
	}

	public List<OrderSupplierMaterRealPo> getOrderSupMaterRealListByOrdIdMaterId(int ordId, int ordMaterId, int ordSupId, int ordCustId)
			throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierMaterRealPo o where  o.ordSupId = '" + ordSupId + "' and o.ordId='" + ordId + "' and o.ordMaterId='"
				+ ordMaterId + "' ");
		List<OrderSupplierMaterRealPo> list = template.find(ql.toString(), null);
		return list;
	}

	public List<OrderSupplierMaterRealPo> getOrderSupMaterRealListByOrdIdMaterId(int ordId, int ordMaterId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierMaterRealPo o where o.ordId='" + ordId + "' and o.ordMaterId='" + ordMaterId + "' ");
		List<OrderSupplierMaterRealPo> list = template.find(ql.toString(), null);
		return list;
	}

	// 取得待打印的订单 根据 供货商 日期 材料id ，客户id
	public List<OrderSupplierMaterRealPo> getOrderSupMaterRealListBySupIdOrdDateMaterIdAndCustId(int ordSupId, String ordDate, int materId,
			String custId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select a ");
		ql.append(" from OrderSupplierMaterRealPo a,OrderSupplierPo b where a.ordId=b.ordId and b.ordState!=5  and a.ordSupId = b.ordSupId AND b.ordDate ='"
				+ ordDate + "' AND b.ordSupId ='" + ordSupId + "' AND a.ordMaterId =" + materId);

		ql.append(" AND b.ordCustId ='" + custId + "'");

		ql.append(" AND b.ordState in(" + CommonType.ORD_STATE_1 + "," + CommonType.ORD_STATE_2 + "," + CommonType.ORD_STATE_21 + ","
				+ CommonType.ORD_SUP_WAIT + ")");

		List<OrderSupplierMaterRealPo> list = template.find(ql.toString(), null);
		return list;
	}

	// 取得已送货订单 根据 供货商 日期 材料id ，客户id
	public List<OrderSupplierMaterRealPo> getOrderSupMaterRealListBySupIdOrdDateMaterIdAndCustIdForNotPrt(int ordSupId, String ordDate, int materId,
			String custId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select a ");
		ql.append(" from OrderSupplierMaterRealPo a,OrderSupplierPo b where a.ordId=b.ordId and b.ordState!=5  and a.ordSupId = b.ordSupId AND b.ordDate ='"
				+ ordDate + "' AND b.ordSupId ='" + ordSupId + "' AND a.ordMaterId =" + materId);
		ql.append(" AND b.ordCustId ='" + custId + "'");
		
		ql.append(" AND b.ordState not in(" + CommonType.ORD_STATE_1 + "," + CommonType.ORD_STATE_2 + "," + CommonType.ORD_STATE_21 + ","
				+ CommonType.ORD_SUP_WAIT + ")");

		List<OrderSupplierMaterRealPo> list = template.find(ql.toString(), null);
		return list;
	}

	@Override
	public PaginationSupport listCustOrder(PageController pageController, OrderSupplierVo orderSupplierVo) throws GenericException {

		StringBuffer ql = new StringBuffer();
		ql.append(" SELECT o.oid, o.ord_id, o.ord_cust_id, o.ord_sup_id, o.ord_state, o.ord_date , o.ord_day, o.update_time, o.insert_by, o.ord_value, b.shop_name, c.sup_companyname,o.ord_payment_state,o.ord_value_real,o.commit_deliver_state FROM t_order_supplier o ,t_shop b,t_supplier c WHERE o.ord_cust_id = b.shop_id AND o.ord_sup_id = c.sup_id AND ord_cust_id = '"
				+ orderSupplierVo.getOrdCustId() + "'");

		if (orderSupplierVo.getOrdDate() != null && !orderSupplierVo.getOrdDate().equals("")) {
			ql.append(" and o.ord_date  = '");
			ql.append(orderSupplierVo.getOrdDate());
			ql.append("'");
		}
		if (orderSupplierVo.getOrdState() != 0) {
			ql.append(" and o.ord_state  = '");
			ql.append(orderSupplierVo.getOrdState());
			ql.append("'");
		}
		ql.append(" ORDER BY  o.ord_id");

		return this.findByNativeQuery(ql.toString(), pageController);
	}

	@Override
	public PaginationSupport listCustOrderAllForpurchase(PageController pageController, OrderSupplierVo orderSupplierVo) throws GenericException {

		StringBuffer ql = new StringBuffer();
		ql.append(" SELECT o.oid, o.ord_id, o.ord_cust_id, o.ord_sup_id, o.ord_state, o.ord_date , o.ord_day, o.update_time, o.insert_by, o.ord_value, b.shop_name, c.sup_companyname,o.ord_payment_state,o.ord_value_real,o.commit_deliver_state FROM t_order_supplier o ,t_shop b,t_supplier c WHERE o.ord_cust_id = b.shop_id AND o.ord_sup_id = c.sup_id ");

		if (orderSupplierVo.getOrdDate() != null && !orderSupplierVo.getOrdDate().equals("")) {
			ql.append(" and o.ord_date  = '");
			ql.append(orderSupplierVo.getOrdDate());
			ql.append("'");
		}
		if (orderSupplierVo.getOrdState() != 0) {
			ql.append(" and o.ord_state  = '");
			ql.append(orderSupplierVo.getOrdState());
			ql.append("'");
		}
		if (orderSupplierVo.getOrdCustName() != null && !orderSupplierVo.getOrdCustName().equals("")) {
			ql.append(" and b.shop_name like '%");
			ql.append(orderSupplierVo.getOrdCustName());
			ql.append("%'");
		}
		ql.append(" AND EXISTS (SELECT 1 FROM t_shop s WHERE s.`shop_id` = b.`shop_id` AND s.`company_user` = '" + orderSupplierVo.getCompanyUser()
				+ "')");

		ql.append(" ORDER BY  o.ord_id");

		return this.findByNativeQuery(ql.toString(), pageController);
	}

	@Override
	public OrderSupplierPo getOrderSup(String ordId, String ordCustId, String ordSupId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierPo o where o.ordId='" + ordId + "' and o.ordCustId='" + ordCustId + "' and o.ordSupId='" + ordSupId + "'");
		List<OrderSupplierPo> list = template.find(ql.toString(), null);
		return list.get(0);
	}

	public List<OrderSupplierPo> isExistOrderSup(String ordCustId, String ordSupId, String orderDay, int materId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierPo o,OrderSupplierMaterPo m where o.ordId = m.ordId AND o.ordCustId=" + ordCustId + "and o.ordSupId="
				+ ordSupId + " AND o.ordDate = '" + orderDay + "' AND m.ordMaterId = '" + materId + "'");
		List<OrderSupplierPo> list = template.find(ql.toString(), null);
		return list;
	}

	@Override
	public List<OrderSupplierPo> getOrderSupList(String ordId, String ordCustId, String ordSupId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierPo o where o.ordId=" + ordId + "and o.ordCustId=" + ordCustId + "and o.ordSupId=" + ordSupId);
		List<OrderSupplierPo> list = template.find(ql.toString(), null);
		return list;

	}

	public List<OrderSupplierPo> getOrderSupListByOrdIdAndSupId(long ordId, long ordSupId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierPo o where o.ordId=" + ordId + " and o.ordSupId=" + ordSupId);
		List<OrderSupplierPo> list = template.find(ql.toString(), null);
		return list;

	}

	// 短讯用到的供货商
	public List<SupplierPo> getOrderSupList(String ordId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select s ");
		ql.append(" from SupplierPo s WHERE EXISTS (SELECT 1 FROM  OrderSupplierPo o WHERE o.ordId ='" + ordId + "'  AND o.ordSupId = s.supplierId) ");
		List<SupplierPo> list = template.find(ql.toString(), null);
		return list;
	}

	public List<SupplierPo> getOrderSupList(String ordId, String materId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select s ");
		ql.append(" from SupplierPo s WHERE EXISTS (SELECT 1 FROM  OrderSupplierPo o WHERE o.ordId ='" + ordId + "'  AND o.ordSupId = s.supplierId) ");
		List<SupplierPo> list = template.find(ql.toString(), null);
		return list;
	}

	public List<Object[]> getSupUpdateOrderMater(String ordId, String supId, String materId) throws GenericException {
		StringBuffer ql = new StringBuffer();
		ql.append(" SELECT o.ord_date,m.mater_name, m.specifications, om.ord_mater_weight, m.unit,(SELECT s1.sup_mobile FROM t_supplier s1 WHERE s1.sup_id = om.ord_sup_id) FROM t_order_supplier_mater om, t_order_supplier o , t_material m WHERE om.ord_id = o.ord_id AND om.ord_sup_id = o.ord_sup_id AND om.ord_sup_id = '"
				+ supId
				+ "' AND om.ord_id = '"
				+ ordId
				+ "' AND m.mater_id = om.ord_mater_id AND om.ord_mater_id ='"
				+ materId
				+ "' AND EXISTS (SELECT 1 FROM t_supplier s WHERE s.sup_id = om.ord_sup_id AND s.note_flag =1) ");
		List list = this.entityManager.createNativeQuery(ql.toString()).getResultList();
		return list;
	}

	public OrderSupplierPo getOrderSupByOrdIdSupId(String ordId, String ordSupId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from OrderSupplierPo o where o.ordId=" + ordId + " and o.ordSupId=" + ordSupId);
		List<OrderSupplierPo> list = template.find(ql.toString(), null);
		return list.get(0);
	}

	@Override
	public void updateOrderSupplierPo(OrderSupplierPo orderSupplierPo) throws GenericException {
		this.merge(orderSupplierPo);
	}

	public void deleteOrderSupperMater(String ordId, String ordMaterId, String ordSupId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" delete OrderSupplierMaterPo o where o.ordMaterId='" + ordMaterId + "' and o.ordSupId ='" + ordSupId + "' and o.ordId='" + ordId
				+ "'");
		template.executeUpdate(ql.toString());

		StringBuffer q2 = new StringBuffer();
		q2.append(" delete OrderSupplierMaterNeedPo o where o.ordMaterId='" + ordMaterId + "' and o.ordSupId ='" + ordSupId + "' and o.ordId='"
				+ ordId + "'");
		template.executeUpdate(q2.toString());

		StringBuffer q3 = new StringBuffer();
		q3.append(" delete OrderSupplierMaterRealPo o where o.ordMaterId='" + ordMaterId + "' and o.ordSupId ='" + ordSupId + "' and o.ordId='"
				+ ordId + "'");
		template.executeUpdate(q3.toString());

		StringBuffer q4 = new StringBuffer();
		q4.append(" delete OrderCustFoodPo o where o.ordMaterId='" + ordMaterId + "' and o.ordId='" + ordId + "'");
		template.executeUpdate(q4.toString());
	}

	public BigDecimal computeValueReal(int ordId, int supId) throws GenericException {

		StringBuffer ql = new StringBuffer();
		ql.append("SELECT IFNULL(SUM(ord_mater_value),0) FROM t_order_supplier_mater_reality WHERE ord_id = '" + ordId + "' AND ord_sup_id='" + supId
				+ "' and return_goods ='0'");
		List list = this.entityManager.createNativeQuery(ql.toString()).getResultList();
		return new BigDecimal(list.get(0).toString());
	}

	public BigDecimal computeValueRealCost(int ordId, int supId) throws GenericException {
		StringBuffer ql = new StringBuffer();
		ql.append("SELECT IFNULL(ROUND(SUM(ord_mater_value_cost),2),0) FROM t_order_supplier_mater_reality WHERE ord_id = '" + ordId
				+ "' AND ord_sup_id='" + supId + "' and return_goods ='0'");
		List list = this.entityManager.createNativeQuery(ql.toString()).getResultList();
		return new BigDecimal(list.get(0).toString());
	}

	public BigDecimal computeValue(int ordId, int supId) throws GenericException {

		StringBuffer ql = new StringBuffer();
		ql.append("SELECT IFNULL(ROUND(SUM(ord_mater_value),2),0) FROM t_order_supplier_mater WHERE ord_id = '" + ordId + "' AND ord_sup_id='"
				+ supId + "'");
		List list = this.entityManager.createNativeQuery(ql.toString()).getResultList();
		return new BigDecimal(list.get(0).toString());
	}

	public void updateOrderSupplierMaterReal(OrderSupplierMaterRealPo po) throws GenericException {
		this.merge(po);
	}

	// sendmessage for detail message
	public List<Object[]> getSupNoteMessageContent(String ordId, int supId) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT m.mater_name, m.specifications, o.ord_mater_weight, m.unit FROM t_order_supplier_mater o, t_material m WHERE o.ord_id = '"
				+ ordId + "' AND o.ord_sup_id = '" + supId + "' AND m.mater_id = o.ord_mater_id ");
		List list = this.entityManager.createNativeQuery(sql.toString()).getResultList();
		return list;
	}
}
